import React from "react";
import {useRoutes, Outlet, Navigate} from "react-router-dom";
import {lazyLoading} from "@/utils";
import AuthComponent from "@/components/AuthComponent";
import Index from "@/pages/Index";
import {DatabaseOutlined, HomeOutlined,MedicineBoxOutlined} from "@ant-design/icons";

const routes = [
    {
        path: "/",
        element:(
            <AuthComponent>
                <Index/>
            </AuthComponent>
        ),children:[
            {
                // 主页
                path:"/",
                label:"主页",
                icon:<HomeOutlined />,
                element:lazyLoading("Home")
            },
            {
                // 数据管理
                path:"/cmn",
                label:"数据管理",
                icon:<DatabaseOutlined />,
                element:<Outlet/>,
                children:[
                    {
                        path:"/cmn",
                        label:"数据管理",
                        isHide:true,// 是否隐藏
                        element:<Navigate to={"/cmn/dict"}/>
                    },
                    {
                        // 数据字典
                        path:"/cmn/dict",
                        label:"数据字典",
                        element:lazyLoading("cmn/dict")
                    }
                ]
            },{
                // 医院管理
                path:"/hospital",
                label:"医院管理",
                icon:<MedicineBoxOutlined />,
                element:<Outlet/>,
                children: [
                    {
                        path:"/hospital",
                        // label:"医院管理",
                        element:<Navigate to={"/hospital/hospitalSet"}/>,
                        isHide: true
                    },{
                        path:"/hospital/hospitalSet",
                        element: lazyLoading("hospital/hospitalSet"),
                        label:"医院设置"
                    },{
                        path:"/hospital/hospitalList",
                        element: lazyLoading("hospital/hospitalList"),
                        label:"医院列表"
                    }
                ]
            }
        ]
    }, {
        path: "/login",
        element: lazyLoading("Login")
    }, {
        path: "*",
        element: lazyLoading("NotFound")
    }
];

// 响应路由配置
export default function () {
    // /cmn/dict
    return useRoutes(routes)
}
// 响应侧边栏
export const renderSlider = function(){
    return (routes.find(v=>v.path==="/") as any).children;
}
